#define _CRT_SECURE_NO_WARNINGS

#include<iostream>

#include"Mymemory.h"

using namespace std;


void auto_test1()
{
	myptr::auto_ptr<int> a(new int);
	*a = 10;
	cout << *a << endl;
	myptr::auto_ptr<int> b;
	b = a;

	cout << *b << endl;
	cout << a.get() << endl;


	myptr::auto_ptr<pair<int,int>> c(new pair<int, int>);
	c->first = 1;
	c->second = 2;
	auto d = c;
	cout << d->first << d->second << endl;

	
}

void unique_test2()
{
	std::default_delete<int> d;
	myptr::unique_ptr<int> u1;
	myptr::unique_ptr<int> u2(nullptr);
	myptr::unique_ptr<int> u3(new int);
	myptr::unique_ptr<int,std::default_delete<int>> u4(new int, d);
	myptr::unique_ptr<int> u5(new int, myptr::default_delete<int>());
	

	std::cout << "u1: " << (u1 ? "not null" : "null") << '\n';
	std::cout << "u2: " << (u2 ? "not null" : "null") << '\n';
	std::cout << "u3: " << (u3 ? "not null" : "null") << '\n';
	std::cout << "u4: " << (u4 ? "not null" : "null") << '\n';
	std::cout << "u5: " << (u5 ? "not null" : "null") << '\n';

	myptr::unique_ptr<int> a(myptr::unique_ptr<int>(new int{3}));

	cout << *a << endl;

}

void unique_test3()
{
	myptr::unique_ptr<int> a(new int);
	*a = 10;
	cout << *a << endl;
	myptr::unique_ptr<int> b;

	myptr::unique_ptr<pair<int, int>> c(new pair<int, int>);
	c->first = 1;
	c->second = 2;


	myptr::unique_ptr<int[]> d ( myptr::unique_ptr<int[]>(new int[2]{1,2}));


	for (int i = 0; i < 2; i++)
	{
		cout << d[i] << " ";
	}


}
void shared_test1()
{
	myptr::shared_ptr<int> a1(new int);
	myptr::shared_ptr<int> a2(new int, [](int* ptr) { delete ptr; });
	auto cmp = [](int* ptr) {delete[] ptr; };
	myptr::shared_ptr<int> a3(new int[5]{1,2,3,4,5}, cmp);
	a3[3] = 5;
	std::shared_ptr<int[]> a4(new int[5]);
	a4[3] = 6;

	for (int i = 0; i < 5; i++) cout << a3[i] << " ";

}

int main()
{
	shared_test1();
	return 0;
}